﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.Generic;
namespace WPFExcelReport
{

    public partial class RZPRULES : VBPRULES
    {
        public override void Reset()
        {
            base.Reset();
        }
        private void btnResetP_Click(object sender, RoutedEventArgs e)
        {
            Reset();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            CHKFLOW();
        }
        public void CHKFLOW()
        {
            if (dwMaster == null)
                return;
            string ARTSTAGE = dwMaster["ARTSTAGE"].ToString();
            FLOW = "";
            FLOW = dwMaster["UNDES"].ToString();
            if (FLOW.Length > 2)
                return;
            switch (app.company)
            {
                case "YGR":
                    string GSFACH = dwMaster["P2"].ToString();
                    FLOW = "";
                    if (System.Convert.ToDouble(GSFACH) > 1)
                    {
                        FLOW = "XS000002";
                    }
                    else
                    {
                        FLOW = "XS000001";
                    }
                    break;

                case "SXN":
                case "UBT":
                    string ZUART = dwMaster["P10"].ToString();
                    switch (ZUART)
                    {
                        default:
                        case "F":
                            FLOW = "PD000001";
                            break;
                        case "C":
                            FLOW = "HZ000001";
                            break;
                    }
                    break;
                default:
                    FLOW = "HZ000001";
                    break;
            }
        }
        public string CHKAPZUORD()
        {
            string key = "";

            return key;
        }

        public override void OnEXAUFChg(string exauf)
        {
            try
            {
                if (exauf.Length < 74)
                    return;
                IsNew = true;
                ARTST = exauf.Substring(11, 1);
                ART = exauf.Substring(12, 20);
                VAR = exauf.Substring(32, 2).PadRight(3);
                FARBE = exauf.Substring(34, 10);
                FINISH = exauf.Substring(44, 10);
                DESS = exauf.Substring(54, 10);
                COLORIT = exauf.Substring(64, 10);
                RLPRART = ART + VAR + FARBE + FINISH + DESS + COLORIT;
                //ART + VAR.PadRight(3) + FARBE.PadRight(10) + FINISH.PadRight(10) + DESS.PadRight(10) + COLORIT.PadRight(10);
                if (KRS == "")
                {
                    throw new Exception("前缀");
                }
                if (RLPRART == "")
                {
                    throw new Exception("品种");
                }
                TBMain.Clear();
                dwData = TBMain.NewRow();

                PM["RUNID"] = this.RUNID;
                PM["KRS"] = exauf.Substring(0, 2);
                PM["AUFART"] = "VA";
                PM["ORDERNUM"] = exauf.Substring(0, 11);
                PM["LFD"] = exauf.Substring(2, 6);
                PM["RELOADABK"] = false;
                string ABAUF = TMV.VABK.NEWABK(PM);
                LFD = ABAUF.Substring(2, 6);
                POS = EXAUF.Substring(8, 3);
                PM["ORDERNUM"] = ABAUF.Substring(0, 2) + LFD + POS + "VA ";
                PM["COLOR"] = "VA ";
                PM["AUFTYP"] = "V";
                PM["ARTSTAGE"] = "Z";
                //PM["VKAUF"] = pm["ORDERNUM"];
                PM["VKPAUF"] = KRS + LFD + POS;
                PM["VKPQTY"] = 0;//
                PM["VKAUF"] = "                  ";//
                PM["UNDES"] = FLOW;
                PM["DELDATE"] = TMV.date;
                PM["STARTDATE"] = TMV.date;
                PM["P6"] = exauf.Substring(129, 10);//PARTIE
                bool IsExists = TMV.NEWPLAN(PM);

                if (!IsExists)
                {
                    if (dwMaster == null)
                        return;
                    TMV.UPRULES01(dwMaster);
                    MessageInfo msg = new MessageInfo();
                    RLPRART = ART + VAR.PadRight(3) + FARBE.PadRight(10) + FINISH.PadRight(10) + DESS.PadRight(10) + COLORIT.PadRight(10);
                    msg.Sender = this.RUNID;
                    msg.MSGTYPE = "RZABPNEW";
                    msg.ACTION = "RZABPNEW";
                    msg.AUFTYP = "V";
                    msg.WAKZ = "F";
                    msg.ART = ART;
                    msg.VAR = VAR;
                    msg.FARBE = FARBE;
                    msg.BESCHICH = FINISH;
                    msg.DESS = DESS;
                    msg.COLORIT = COLORIT;
                    msg.ORDER = (string)PM["ORDERNUM"];
                    msg.Where = app.User;
                    VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
                }
                vwMaster.View.MoveCurrentToFirst();
                base.OnEXAUFChg(exauf);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
    }
